package com.example.osixaffairssystem.controller;

import com.example.osixaffairssystem.domain.Result;
import com.example.osixaffairssystem.domain.model.Account;
import com.example.osixaffairssystem.service.AccountService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequiredArgsConstructor
public class AccountController {

    final AccountService accountService;

    @PostMapping("/login")
    public Result login(@RequestBody Account account) {
        log.info("login");
        account = accountService.login(account);
        if (account == null) {
            return new Result(HttpStatus.UNAUTHORIZED.value(), "账号或密码错误", null);
        }
        return Result.success(account);
    }

}
